package com.example.jasonrpc.client.byRegistry;

import com.example.jasonrpc.client.ClientConfig;
import com.example.jasonrpc.client.RpcClient;
import com.example.jasonrpc.common.ReflectionUtils;

/**
 * 通过注册中心获取服务和主机，端口信息的rpc客户端
 * 特点是主机，端口是归属于某个服务的
 */
public class RpcClientByRegistry extends RpcClient {

    public RpcClientByRegistry(ClientConfig clientConfig) {
        super(clientConfig);
    }

    @Override
    protected void init(ClientConfig config) {
        this.encoder = ReflectionUtils.newInstance(config.getEncoderClass());
        this.decoder = ReflectionUtils.newInstance(config.getDecoderClass());
        this.selector = ReflectionUtils.newInstance(config.getSelectorClass());
        // 注册中心的服务类名与ip/port关联
        this.selector.init(config.getDirectories(), config.getConnectCount(), config.getTransportClientClass());
    }
}
